{# 美化用户中心 #}
{% extends 'base.html' %}
{% block content %}
<h3>用户中心 - {{ current_user.username }}</h3>

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item">
    <button class="nav-link active" id="goods-tab" data-bs-toggle="tab" data-bs-target="#goods">我的发布</button>
  </li>
  <li class="nav-item">
    <button class="nav-link" id="comments-tab" data-bs-toggle="tab" data-bs-target="#comments">我的留言</button>
  </li>
  <li class="nav-item">
    <button class="nav-link" id="upload-tab" data-bs-toggle="tab" data-bs-target="#upload">文件上传</button>
  </li>
</ul>

<div class="tab-content mt-3">
  <div class="tab-pane fade show active" id="goods">
    {% for g in goods_list %}
      <div class="card mb-2">
        <div class="card-body">
          <h5>{{ g.title }}</h5>
          <p>￥{{ g.price }} | {{ g.condition }} | {{ g.create_time.strftime('%Y-%m-%d') }}</p>
          <a href="/goods/detail/{{ g.id }}" class="btn btn-sm btn-outline-primary">查看</a>
          <a href="/goods/edit/{{ g.id }}" class="btn btn-sm btn-success">编辑</a>

          <form action="/goods/delete/{{ g.id }}" method="post" style="display: inline">
              <button class="btn btn-sm btn-danger" onclick="return confirm('确定要删除该商品吗?')">删除</button>
          </form>

          {#商品上架、下架#}
          <a href="{{ url_for('goods.toggle_goods_status', goods_id=g.id) }}" >
            {% if g.is_sold %}
                <span class="btn btn-sm btn-warning">上架</span>
            {% else %}
                <span class="btn btn-sm btn-danger">下架</span>
            {% endif %}
          </a>
        </div>
      </div>
    {% else %}
      <p>你还没有发布任何商品。</p>
    {% endfor %}
  </div>

  <div class="tab-pane fade" id="comments">
    {% for msg in messages %}
      <div class="card mb-2">
        <div class="card-body">
          <p>{{ msg.content }}</p>
          <small>留言于 <a href="/goods/detail/{{ msg.goods.id }}">{{ msg.goods.title }}</a></small>
        </div>
      </div>
    {% else %}
      <p>你还没有发布任何留言。</p>
    {% endfor %}
  </div>

  {#头像上传#}
  <div class="tab-pane fade" id="upload">
      <div class="card mb-2">
        <div class="card-body">
          <a href="/profile/avatar">头像上传</a>
        </div>
      </div>
  </div>

</div>
{% endblock %}